
<?php
require_once("inc.member.php");

$this_title="$vars[member_title] &raquo; ".__("Voucher Market");
$page_title=__("Voucher Market");
$content_title=__("Voucher Market");

$purchase_share=$vars["file"]["member"]["purchase_share"];
$sell_share=$vars["file"]["member"]["sell_share"];

$item_per_page=$vars["user_item_per_page"];

//tab
$css="<link rel='stylesheet' type='text/css' href='".CSS_URL."/tab/tab".(USER_BROWSER=='msie'? "-ie" : "").".css' />\n";
$mamount = @mysql_result(mysql_query("select sum(mwallet) from $db->users where status='normal' and mwallet>0 group by status"), 0);$cashflow_amount = @mysql_result(mysql_query("select value from $db->settings where param='cashflow'"), 0);
$tab="<div class='widget'>			        <div class='widget-content'>			            <table class='table table-striped table-highlight'>			            <tr><td>".__('Total Buy Units')."</td><td>".__('Total Sell Units')."</td></tr>			            <tr><td>".number_format($cashflow_amount,2)."</td><td>".number_format($mamount,2)."</td></tr>			            </table>
<div class='tabs-panel' style='width:97%;'><%tab_content%></div>";	

$count_sql = "SELECT count(*) FROM $db->member_mwallet_record WHERE uid=".$uid;$record_sql = "SELECT * FROM $db->member_mwallet_record WHERE uid=".$uid." ORDER BY id LIMIT <%limit_start%>, <%limit%>";


//#####LIST EWALLET HISTORY#####

$cur_page=$_GET["nav"];

$total_record=@mysql_result(mysql_query($count_sql), 0);

$total_page=ceil($total_record/$item_per_page);

$page=($cur_page? ($cur_page>$total_page? $total_page : ($cur_page<1? 1 : $cur_page)) : 1);

$limit_start=($page-1)*$item_per_page;

$nav_link=format_page($page, $total_page, 15);

$this_page_total=@mysql_num_rows($r=mysql_query(str_replace("<%limit_start%>", $limit_start, str_replace("<%limit%>", $item_per_page, $record_sql))));

$k=0;

$is_free = @mysql_result(mysql_query("select is_free from $db->users where id='$uid'"), 0) or 0;

if($_GET['action']=="share" || !$_GET['action']){
		
	for($i=0;$i<$this_page_total;$i++){
	
		$p=mysql_fetch_assoc($r);
		
		if($p['trade_date']<=date('Y-m-d') && $is_free==0)
			$link = "<a href='".$vars['file']['member']['cash_flow_program']."?action=sell&sell_id=$p[id]' onclick=\"return confirm('".__("Are you sure you want to sell?")."')\">".__("Sell")."</a>";
		else
			$link = __("Pending");
		
		$his_row.="
		
			<tr class='row$k'>
		
		  	<td>".($i+1)."</td>
		
		  	<td class='number'>".$p['descr']."</td>
		
		  	<td class='number'>".($p['type']=='credit'?number_format($p['amount'],2):'0.00')."</td>
		
		  	<td class='number'>".($p['type']=='debit'?number_format($p['amount'],2):'0.00')."</td>				  	<td class='number'>".number_format($p['bal'],2)."</td>
		
		  	<td>".date($vars['date_format'], strtotime($p['cdate']))."</td>
		
		 	</tr>";		
		
	 	$k=1-$k;
	}

}

//listing text

$listing_text=replace_tag(__("<%x%> <%title%> <%record%>."), array("<%x%>"=>"$total_record", "<%title%>"=>__("Voucher Market"), "<%record%>"=>$total_record>1? __("records") : __("record")));



//listing
if($_GET['action']=="share" || !$_GET['action']){
	
	$his_list=

	"<h2>".replace_tag(__("<%title%> History"), array("<%title%>"=>__("Voucher Market")))."</h2>
	
	$listing_text $nav_link
	
	<table class='pbl_table'>
	
	 <tr class='pbl_header'>
	
	  <td>".__("Trans#")."</td>
	
	  <td>".__("Description")."</td>
	
	  <td>".__("Credit")."</td>
	
	  <td>".__("Debit")."</td>
	
	  <td>".__("Balance")."</td>		  <td>".__("Date")."</td>
	 </tr>
	
	 $his_row
	
	</table>
	
	$nav_link";	
	
}


$content=$errmsg.$his_list;

//$content="<h2>$page_title</h2>$matrix";
$content=str_replace("<%tab_content%>", $content, $tab);

print format_member_page($content, $this_title, $content_title, $css . $inc_jvscript);

?>
